package com.hdjd.service.imp;

import com.hdjd.dao.AccountDao;
import com.hdjd.dao.SchoolDao;
import com.hdjd.entities.Account;
import com.hdjd.entities.School;
import com.hdjd.service.SchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 刘子强
 * 2021/1/28 9:20
 */
@Service
public class SchoolServiceImp implements SchoolService {
    @Autowired
    private SchoolDao schoolDao;
    @Autowired
    private AccountDao accountDao;

    //查询学校集合
    @Override
    public List<School> selectSchoolList(String schProvince, String schName, Integer pageCurrent, Integer pageSize) {
        List<School>  schoolList = this.schoolDao.selectSchoolList(schProvince, schName, pageSize*(pageCurrent-1), pageSize);
        return schoolList;
    }

    //根据院校id查询院校信息
    @Override
    public School selectSchoolBySchoolId(Integer schoolId) {
        School school = this.schoolDao.selectSchoolBySchoolId(schoolId);
        return school;
    }

    //根据院校id修改院校信息
    @Override
    public boolean updateSchoolBySchoolId(School school) {
        boolean flag = this.schoolDao.updateSchoolBySchoolId(school);
        return flag;
    }

    // 新增院校
    @Override
    public boolean insertSchool(School school) {
        boolean flag = this.schoolDao.insertSchool(school);
        return flag;
    }

    //修改院校状态
    @Override
    public boolean updateSchoolStatusBySchoolId(Integer schoolId, Integer schStatus) {
        boolean flag = this.schoolDao.updateSchoolStatusBySchoolId(schoolId, schStatus);
        return flag;
    }

    //查询出所有院校，无分页
    @Override
    public List<School> selectAllSchools() {
        List<School>  allSchools = this.schoolDao.selectAllSchools();
        return allSchools;
    }

    //查询待审核的商家申请
    @Override
    public List<Account> businessApplyNeedCheck(Integer schoolId, Integer pageCurrent, Integer pageSize) {
        List<Account> accounts = this.accountDao.businessApplyNeedCheck(schoolId, (pageCurrent-1)*pageSize, pageSize);
        return accounts;
    }

    //统计待审核的商家申请数据笔数
    @Override
    public Integer countBusinessApplyNeedCheck(Integer schoolId) {
        Integer count = this.accountDao.countBusinessApplyNeedCheck(schoolId);
        return count;
    }

    //查询已审核的商家申请
    @Override
    public List<Account> businessApplyChecked(Integer schoolId, Integer pageCurrent, Integer pageSize) {
        List<Account> accounts = this.accountDao.businessApplyChecked(schoolId, (pageCurrent-1)*pageSize, pageSize);
        return accounts;
    }

    //统计已审核的商家申请数据笔数
    @Override
    public Integer countBusinessApplyChecked(Integer schoolId) {
        Integer count = this.accountDao.countBusinessApplyChecked(schoolId);
        return count;
    }

    //查询已审核的配送员申请
    @Override
    public List<Account> deliveryManApplyNeedCheck(Integer schoolId, Integer pageCurrent, Integer pageSize) {
        List<Account> accounts = this.accountDao.deliveryManApplyNeedCheck(schoolId, (pageCurrent-1)*pageSize, pageSize);
        return accounts;
    }

    //统计待审核的配送员申请数据笔数
    @Override
    public Integer countDeliveryManApplyNeedCheck(Integer schoolId) {
        Integer count = this.accountDao.countDeliveryManApplyNeedCheck(schoolId);
        return count;
    }

    //查询已审核的配送员申请
    @Override
    public List<Account> deliveryManApplyChecked(Integer schoolId, Integer pageCurrent, Integer pageSize) {
        List<Account> accounts = this.accountDao.deliveryManApplyChecked(schoolId, (pageCurrent-1)*pageSize, pageSize);
        return accounts;
    }

    //统计已审核的配送员申请数据笔数
    @Override
    public Integer countDeliveryManApplyChecked(Integer schoolId) {
        Integer count = this.accountDao.countDeliveryManApplyChecked(schoolId);
        return count;
    }

    //审核通过商家申请
    @Override
    public boolean passBusinessApply(Integer accId) {
        Account account = new Account();
        account.setAccId(accId);
        account.setBusinessSign(2);
        account.setRole(2);

        boolean flag = this.accountDao.updateAccountByAccId(account);
        return flag;
    }

    //审核不通过商家申请
    @Override
    public boolean unPassBusinessApply(Integer accId) {
        Account account = new Account();
        account.setAccId(accId);
        account.setBusinessSign(3);

        boolean flag = this.accountDao.updateAccountByAccId(account);
        return flag;
    }

    //审核通过配送员申请
    @Override
    public boolean passDeliverymanApply(Integer accId) {
        Account account = new Account();
        account.setAccId(accId);
        account.setDeliverymanSign(2);
        account.setRole(3);

        boolean flag = this.accountDao.updateAccountByAccId(account);
        return flag;
    }

    //审核不通过配送员申请
    @Override
    public boolean unPassDeliverymanApply(Integer accId) {
        Account account = new Account();
        account.setAccId(accId);
        account.setDeliverymanSign(3);

        boolean flag = this.accountDao.updateAccountByAccId(account);
        return flag;
    }


}
